package com.lanhao.aot.excel;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

public class TxtUtil3 {
	public static final String FILE_ALL = "D:/摄像头数据/安康已激活设备.TXT";
	
	
	public static void main(String[] args) {
		
		ExcelReader reader = ExcelUtil.getReader("D:/摄像头数据/FinalData.xlsx");
		List<List<Object>> readFinal = reader.read();
		Map<String, CameraData> finaMap = new HashMap<>();
		for (int i = 1; i < readFinal.size(); i++) {
			List<Object> list = readFinal.get(i);
			String sn = (String) list.get(0);
			String cmei = (String) list.get(1);
			String mac = (String) list.get(2);
			String version = (String) list.get(3);
			String model = (String) list.get(4);
			String online = (String) list.get(5);
			CameraData cameraData = new CameraData();
			cameraData.setSn(sn);
			cameraData.setCmei(cmei);
			cameraData.setMac(mac);
			cameraData.setVersion(version);
			cameraData.setModel(model);
			cameraData.setOnline(online);
			finaMap.put(cmei, cameraData);
			
		}
		System.out.println("读取final全部数据size=" + finaMap.size());
		
		// 读取集合
		List<String> aleadyData = FileUtil.readLines(new File(FILE_ALL), "UTF-8");
		
		Set<String> aleadyDataSet = new HashSet<String>(aleadyData);
		System.out.println("已激活数据size=" + aleadyDataSet.size());
		
		List<CameraData> filterCameraList = new ArrayList<CameraData>();
		for (String cmei : finaMap.keySet()) {
			CameraData cameraData = finaMap.get(cmei);
			if(aleadyDataSet.contains(cmei)) {
				cameraData.setContains("含");
			} else {
				cameraData.setContains("不含");
			}
			filterCameraList.add(cameraData);
		}
		
		
		// 生成excel
		
		ExcelWriter writer = ExcelUtil.getWriter("D:/摄像头数据/FinalFilterData.xlsx");
		writer.write(filterCameraList, true);
		//关闭writer，释放内存
		writer.close();
		
	}
}
